/*
** ADOBE SYSTEMS INCORPORATED
** Copyright 2012 Adobe Systems Incorporated
** All Rights Reserved.
**
** NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the
** terms of the Adobe license agreement accompanying it.  If you have received this file from a
** source other than Adobe, then your use, modification, or distribution of it requires the prior
** written permission of Adobe.
*/

#pragma once
#include <math.h>

namespace SpaceTriangle
{
	struct vec3
	{
		float x,y,z;

		vec3() : x(0), y(0), z(0) { }

		vec3(float _x, float _y, float _z) : x(_x), y(_y), z(_z) { }

		inline vec3& operator+=(float s) {
			x += s;
			y += s;
			z += s;
			return *this;
		}

		inline vec3& operator+=(const vec3 &rhs) {
			x += rhs.x;
			y += rhs.y;
			z += rhs.z;
			return *this;
		}

		inline vec3& operator/=(float s) {
			x /= s;
			y /= s;
			z /= s;
			return *this;
		}

		inline void rotate2D(float d)
		{
			float c = ::cos(d);
			float s = ::sin(d);
			x = x * c - y * s;
			y = x * s + y * c;
		}

		inline float length() const {
			sqrt(x*x + y*y + z*z);
		}

		inline void normalize()
		{
			*this /= length();
		}
	};

	inline vec3 operator*(float s, const vec3 &rhs) {
		vec3 r;
		r.x = rhs.x * s;
		r.y = rhs.y * s;
		r.z = rhs.z * s;
		return r;
	}

	inline vec3 operator-(const vec3 &lhs, const vec3 &rhs) {
		vec3 r;
		r.x = lhs.x - rhs.x;
		r.y = lhs.y - rhs.y;
		r.z = lhs.z - rhs.z;
		return r;
	}
}